Skip to content

build(docker): Add Linux LSP support by fixing compile_commands.json paths#2303

Open
abhatem wants to merge 1 commit intoTheSuperHackers:mainfrom
abhatem:compile-commands
Open

build(docker): Add Linux LSP support by fixing compile_commands.json paths#2303
abhatem wants to merge 1 commit intoTheSuperHackers:mainfrom
abhatem:compile-commands

Conversation

@abhatem
Copy link

@abhatem abhatem commented Feb 13, 2026

Summary

This PR improves the development experience for Linux contributors by making the compile_commands.json generated inside the Docker container usable on the host machine.

Problem

Currently, when building with docker-build.sh, the generated compile_commands.json contains:

  1. Container paths: /build/cnc/... instead of the host's workspace path.
  2. Windows-style backslashes: \ which confuse Linux LSP servers (like clangd/ccls).
  3. Drive letters: Z: references from Wine.

This causes "Go to Definition" and other LSP features to fail in Linux editors (VS Code, Emacs, Neovim) because they cannot locate the source files.

Solution

  1. Added scripts/fix_compile_commands.py: A Python script that:
    • Rewrites container paths to host absolute paths.
    • Normalizes backslashes to forward slashes.
    • Strips Wine drive letters.
  2. Updated scripts/docker-build.sh: Automatically runs the fix script after a successful build if python3 is detected.

Testing

  • Verified docker-build.sh still compiles the game successfully.
  • Verified compile_commands.json is generated and paths are correctly mapped to the host.
  • Verified LSP (clangd) works in Emacs/Eglot on Linux.

Notes

scripts/fix_compile_commands.py was mostly AI generated but human verified and tested

@greptile-apps
Copy link

greptile-apps bot commented Feb 13, 2026

Greptile Overview

Greptile Summary

This PR successfully enables LSP support for Linux developers by automatically fixing compile_commands.json paths after Docker builds. The implementation adds a post-build step that transforms container paths (/build/cnc) to host paths, normalizes Windows backslashes to forward slashes, and strips Wine drive letters.

Key Changes:

  • Added fix_compile_commands() function in docker-build.sh that runs automatically after successful non-interactive builds
  • Created scripts/fix_compile_commands.py to perform path transformations on the JSON compilation database
  • The fix runs conditionally (only if python3 is available and compile_commands.json exists) with graceful error handling

Notes:

  • Previous review comments about missing copyright header and unused re import appear to have been addressed (copyright is present, no re import in current version)
  • The dead code comment about the if path.startswith('/') block with only pass is no longer relevant - that code doesn't exist in the current version
  • Path replacement order in command strings works correctly but relies on final Z: stripping to handle edge cases where /build/cnc is replaced before Z:/build/cnc

Confidence Score: 4/5

  • Safe to merge with minor considerations about path replacement robustness
  • The implementation is well-tested and addresses a real developer experience issue. The bash integration is clean with proper error handling. The Python script logic works correctly, though the string replacement order in the command processing could theoretically cause issues if a Linux path contained 'Z:' (extremely unlikely). Since the author tested it with actual LSP tools and the changes are isolated to developer tooling (not production code), the risk is minimal.
  • No files require special attention - both changes are straightforward tooling improvements

Important Files Changed

Filename Overview
scripts/docker-build.sh Added fix_compile_commands() function to automatically fix compile_commands.json paths after build, with proper error handling
scripts/fix_compile_commands.py New Python script to transform Docker container paths to host paths for LSP support; logic works but replacement order could be more robust

Sequence Diagram

sequenceDiagram
    participant User
    participant docker-build.sh
    participant Docker Container
    participant fix_compile_commands.py
    participant Host Filesystem

    User->>docker-build.sh: Execute build script
    docker-build.sh->>Docker Container: Run build in container
    Docker Container->>Host Filesystem: Generate compile_commands.json<br/>(with container paths /build/cnc)
    docker-build.sh->>fix_compile_commands.py: Run post-build fix script
    fix_compile_commands.py->>Host Filesystem: Read compile_commands.json<br/>from build/docker/
    fix_compile_commands.py->>fix_compile_commands.py: Transform paths:<br/>- /build/cnc → host path<br/>- backslashes → forward slashes<br/>- strip Wine drive letters
    fix_compile_commands.py->>Host Filesystem: Write fixed compile_commands.json<br/>to project root
    docker-build.sh->>User: Build complete, LSP ready
Loading

Last reviewed commit: db5cdaf

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

….json

Added scripts/fix_compile_commands.py to rewrite container paths to host paths and updated scripts/docker-build.sh to automatically run it after build.
@xezon xezon changed the title feat(docker): add Linux LSP support by fixing compile_commands.json paths build(docker): Add Linux LSP support by fixing compile_commands.json paths Feb 15, 2026
@xezon xezon added Enhancement Is new feature or request Minor Severity: Minor < Major < Critical < Blocker Build Anything related to building, compiling Platform Work towards platform support, such as Linux, MacOS labels Feb 15, 2026
Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wild

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Build Anything related to building, compiling Enhancement Is new feature or request Minor Severity: Minor < Major < Critical < Blocker Platform Work towards platform support, such as Linux, MacOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants